<template>
	<view class="fui-wrap">
		<fui-list>
			<fui-list-cell v-for="(item,index) in list" :key="index">
				<view class="item" @click="$navigateTo('parking/records/detail?records_id='+item.id)">
					<view class="line">
						<view class="hang">
							<fui-text text="车牌号：" color="#afafaf" :size="24"></fui-text>
							<platetype :plate_number="item.plate_number" :plate_type="item.plate_type"></platetype>
						</view>
						<view class="hang">
							<fui-text text="入场时间：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.entry_time_txt" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="规则：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.rules_type_txt" color="#000" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="出场时间：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.exit_time_txt" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="状态：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.status_txt" :color="statusColor[item.status]" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="停车时长：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="formatDuration(item.park_time,'minutes')" color="#000" :size="28"></fui-text>
						</view>
					</view>
					<view class="line">
						<view class="hang">
							<fui-text text="费用：" color="#afafaf" :size="24"></fui-text>
							<fui-text :text="item.total_fee?`￥${parseNumber(item.total_fee)}`:``" color="#000" :size="28"></fui-text>
						</view>
						<view class="hang">
							<fui-text text="详情>>" :size="24" decoration="underline"></fui-text>
						</view>
					</view>		
				</view>
			</fui-list-cell>
		</fui-list>
		<fui-empty v-if="list.length===0" :src="`${baseUrl}assets/img/miniapp/empty.png`" title="暂无数据!" :marginTop="200"></fui-empty>
		<filter :param="param" @confirm="doSubmit"></filter>
	</view>
</template>

<script>
	import {methods,baseUrl} from '@/utils/core.js';
	import {formatDuration,parseNumber} from '@/utils/util.js'
	import platetype from '@/components/common/platetype.vue';
	import filter from '@/components/common/filter.vue';
	export default {
		components:{
			platetype:platetype,
			filter:filter
		},
		data() {
			return {
				baseUrl:baseUrl,
				statusColor:{'0':'#000','1':'#000','2':'red','3':'green','4':'green','5':'#ffdd60','6':'#ffdd60','7':'red'},
				status:[],
				list:[],
				page:1,
				endData:false,
				param:{
					plate_number:'',
					starttime:'',
					endtime:''
				}
			}
		},
		onLoad(e) {
			if(e.exception){
				this.status=[2,6,7];
				uni.setNavigationBarTitle({
					title:'出入异常'
				});
			}
			if(e.plate_number){
				this.param.plate_number=e.plate_number;
			}
			this.getList();
		},
		onReachBottom() {
			this.getList();
		},
		onPullDownRefresh() {
			this.list=[];
			this.page=1;
			this.endData=false;
			this.getList(function(){
				uni.stopPullDownRefresh();
			});
		},
		methods: {
			...methods,
			formatDuration,
			parseNumber,
			doSubmit:function(param){
				this.param=param;
				this.list=[];
				this.page=1;
				this.endData=false;
				this.getList();
			},
			getList:function(callback=false){
				this.showPopup=false;
				if(this.endData){
					this.$msg('已经到底了');
					return;
				}
				this.$get('parking/records/list',{
					...this.param,
					status:this.status.join(','),
					page:this.page
				},true).then(res=>{
					this.list=this.list.concat(res);
					this.page++;
					if(res.length<10){
						this.endData=true;
					}	
					if(callback){
						callback();
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
.item{
	display: flex;
	flex-wrap: wrap;
	.line{
		display: flex;
		justify-content: space-between;
		align-items: center;
		width:100%;
		height: 60rpx;
		.hang{
			width: 50%;
			display: flex;
			align-items: center;
		}
	}
}
</style>